<template>
  <div class="search-container">
    <div class="search-wrapper">
      <div class="search-box">
        <div class="search-input-container">
          <i class="iconfont icon-sousuo search-icon"></i>
          <input 
            @keydown.enter="$emit('search', searchText)" 
            type="text" 
            placeholder="搜索您想要的商品..." 
            v-model="searchText"
            class="search-input"
          >
          <button 
            @click="$emit('search', searchText)"
            class="search-button"
            :disabled="!searchText.trim()"
          >
            <i class="iconfont icon-sousuo"></i>
            搜索
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Search",
  data(){
    return{
      searchText: '',
      suggestions: [],
    }
  },
  watch: {
    searchText(newVal) {
      if (newVal.trim()) {
        this.generateSuggestions(newVal);
      } else {
        this.suggestions = [];
      }
    }
  },
  methods: {
    selectTag(tag) {
      this.searchText = tag;
      this.$emit('search', tag);
    }
  }
}
</script>

<style scoped>
.search-container {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 30px 0;
  position: relative;
  overflow: hidden;
  border-radius: 20px;
}

.search-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
  pointer-events: none;
}

.search-wrapper {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

.search-box {
  position: relative;
  margin-bottom: 20px;
}

.search-input-container {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 50px;
  padding: 5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  transition: all 0.3s ease;
}

.search-input-container:focus-within {
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
  transform: translateY(-2px);
}

.search-icon {
  color: #667eea;
  font-size: 20px;
  margin-left: 20px;
  margin-right: 15px;
}

.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  color: #333;
  padding: 15px 0;
}

.search-input::placeholder {
  color: #999;
  font-weight: 400;
}

.search-button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 40px;
  color: white;
  padding: 15px 30px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.search-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}

.search-button:disabled {
  background: #ccc;
  cursor: not-allowed;
  box-shadow: none;
}

.search-button i {
  font-size: 16px;
}

/* 搜索建议 */
.search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  margin-top: 10px;
  z-index: 10;
  overflow: hidden;
}

.suggestion-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover {
  background: rgba(102, 126, 234, 0.1);
}

.suggestion-item i {
  color: #667eea;
  font-size: 16px;
}

/* 
标签 */
.search-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.tags-label {
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  font-weight: 500;
}

.search-tag {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.search-tag:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

</style>